# Contributor: Patrycja Rosa <alpine@ptrcnull.me>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=acmed
pkgver=0.22.1
pkgrel=0
pkgdesc="ACME (RFC 8555) client daemon"
url="https://github.com/breard-r/acmed"
# s390x: https://github.com/nix-rust/nix/issues/1968
arch="all !s390x"
license="MIT"
pkgusers="acmed"
pkggroups="acmed"
makedepends="cargo openssl-dev>3 cargo-auditable"
subpackages="$pkgname-doc $pkgname-openrc $pkgname-tacd $pkgname-tacd-doc:tacd_doc"
install="acmed.pre-install"
source="https://github.com/breard-r/acmed/archive/refs/tags/v$pkgver/acmed-$pkgver.tar.gz
	acmed.confd
	acmed.initd
"

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 -t "$pkgdir"/usr/bin \
		target/release/acmed \
		target/release/tacd

	install -Dm644 -t "$pkgdir"/etc/acmed \
		acmed/config/*
	install -d -o acmed -g acmed "$pkgdir"/var/lib/acmed

	install -Dm644 -t "$pkgdir"/usr/share/man/man8 \
		man/en/acmed.8
	install -Dm644 -t "$pkgdir"/usr/share/man/man5 \
		man/en/acmed.toml.5

	install -Dm755 "$srcdir"/acmed.initd "$pkgdir"/etc/init.d/acmed
	install -Dm644 "$srcdir"/acmed.confd "$pkgdir"/etc/conf.d/acmed
}

tacd() {
	pkgdesc="Standalone tls-alpn-01 challenge validation server"

	amove /usr/bin/tacd
}

tacd_doc() {
	install -Dm644 -t "$pkgdir"/usr/share/man/man8 \
		"$builddir"/man/en/tacd.8

	default_doc
	pkgdesc="Standalone tls-alpn-01 challenge validation server (documentation)"
	install_if="docs $pkgname-tacd=$pkgver-r$pkgrel"
}

sha512sums="
7a288d8f4635de642880a5e46a4dd1f22e51b715d0dd3abc26bd2de813bbebdaa3e5dfe85d08d8ec53a90ad4f52fc9e994faa79bd6755a2ce2f61da9ad7c099f  acmed-0.22.1.tar.gz
2fb5cb330ba4f91c49e34e5808034cbeeb23a9637f4b03cff80ea26338b0a4a232042d7888ee7305afac945402520433828db4064c4274d8ead431aa16a668c1  acmed.confd
126ce93a32c4eace6d41635947c7ecfa3fea3fd731f5ef2b528e911259305e2fdfa115bc78475d6fba57e0717facc27ac4cc341a4c24511c75ef96772e354c1b  acmed.initd
"
